<template>
  <div>
    <div style="text-align:left">
      患者信息：
      <el-tag >姓名：{{patient.real_name}}</el-tag>
      <el-tag >病历号：{{patient.case_number}}</el-tag>
      <el-tag >年龄：{{patient.age}}</el-tag>
      <el-tag >性别：{{patient.gender}}</el-tag>
    </div>
    <el-divider></el-divider>
    <div style="font-size:20px;text-align:left">
      <i class="el-icon-document-checked">在诊患者</i>
    </div>
    <el-divider></el-divider>
    <el-row :gutter="20">
      <el-col :span="6"><el-input v-model="finish_check_patient.case_number" placeholder="请输入患者病历号"></el-input></el-col>
      <el-col :span="6"><el-input v-model="finish_check_patient.real_name" placeholder="请输入患者姓名"></el-input></el-col>
      <el-col :span="2"><el-button @click="getPatient()">搜索</el-button></el-col>
      <el-col :span="10"> </el-input></el-col>
    </el-row>
    <el-table :data="now_all_patient" style="width:80%;margin-top:10px">
      <el-table-column type="index" label="编号" width="50"></el-table-column>
      <el-table-column prop="case_number" label="患者病历号" width="150"></el-table-column>
      <el-table-column prop="real_name" label="患者姓名" width="150"></el-table-column>
      <el-table-column prop="card_number" label="患者身份证" ></el-table-column>
      <el-table-column prop="visit_state" label="患者状态" width="120"></el-table-column>
      <el-table-column prop="visit_date" label="挂号时间" width="260"></el-table-column>
      <el-table-column label="操作" width="120">
        <template slot-scope="scope" >
          <el-button size="mini" @click="toUpdateMedicalRecord(scope.$index,scope.row)">更新病历</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="width:80%;margin-top:10px;text-align:right">
    <el-pagination :total="totalCount" layout="prev,pager,next" 
      :page-size="pageSize" @current-change="nowAllPatientPageChange" >
    </el-pagination>
    </div>

  </div>
</template>
<script>
import qs from 'qs';
import {getSessionLoginUser} from '../../util/util'
import {isNullMessage} from "../../util/util"
export default{
  data(){
    return{
      finish_check_patient:{
        employee_id:'1',
        case_number:"",
        real_name:"",
        nowPageNumber:1,
        pageSize:10,
      },
      patient:{
        real_name:'',
        case_number:'',
        age:"",
        gender:''
      },
      now_all_patient:[],
      totalCount:0,
      pageSize:10,
    }
  },
  methods:{
    //分页（搜索）得到患者信息
    getPatient(){
      this.$http.post("http://localhost:8092/getCheckedPatient",qs.stringify(this.finish_check_patient)).then(
        (resp)=>{
          this.now_all_patient = resp.data.list;
          this.totalCount = resp.data.totalCount
        }
      )
    },
    //更新病历
    toUpdateMedicalRecord(idnex,row){
      sessionStorage.setItem("record_now_patient",JSON.stringify(row));
      this.patient["real_name"] = row.real_name;
      this.patient["case_number"] = row.case_number;
      this.patient["age"] = row.age;
      this.patient["gender"] = row.gender;
      this.$message({
        message:"选择患者："+row.real_name,
        type:"success",
      })
    },
    nowAllPatientPageChange(val){
      this.finish_check_patient.nowPageNumber = val;
      this.getPatient();
    },
    //得到登录用户信息
    initLoginUserInfo(){
      let userInfo = getSessionLoginUser();
      this.finish_check_patient.employee_id = userInfo.id;
      // console.log(this.employee_id);
    },
  },
  mounted:function(){
    this.initLoginUserInfo();
    this.getPatient();
    this.patient = JSON.parse(sessionStorage.getItem("record_now_patient"));
    if(isNullMessage(this,this.patient,'请先选择患者')){
      this.patient={
        real_name:'',
        case_number:'',
        age:'',
        gender:''
      }
    }
  }

}

</script>